<?php

class User_Plugin_Auth_Database extends Auth
{
	public function authenticate($identity, $password)
	{
		$table = Model::getTable('user');
		
		$select = $table -> select() -> where('username=?', $identity) -> orWhere('email=?', $identity);
		
		$user = $table -> fetchRow($select);
		
		if (!is_object($user))
		{
			return Auth::INVALID_IDENTITY;
		}

		if (!$user -> isPassword($password))
		{
			return Auth::INVALID_PASSWORD;
		}

		return $user;
	}

}
